//
//  TeachSimulationCell.m
//  Coach_HaiGeEr
//
//  Created by liuchen on 2018/10/24.
//  Copyright © 2018年 海格尔. All rights reserved.
//

#import "TeachSimulationCell.h"
#import "UIImageView+WebCache.h"
@interface TeachSimulationCell()
@property (nonatomic,weak) UIImageView *headImgView;
@property (nonatomic,weak) UILabel *nameLabel;
@property (nonatomic,weak) UILabel *phoneLabel;
@property (nonatomic,weak) UILabel *areaLabel;
@property (nonatomic,weak) UILabel *carLabel;
@property (nonatomic,weak) UILabel *subjectLabel;
@property (nonatomic,weak) UILabel *achievementLabel;
@end

@implementation TeachSimulationCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubView];
    }
    return self;
}

#pragma mark ==========创建视图==========
- (void)createSubView{
    UIImageView *headImgView = [[UIImageView alloc]init];
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 110*SCALEUNIT, 110*SCALEUNIT) byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(55*SCALEUNIT,55*SCALEUNIT)];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = CGRectMake(0, 0, 110*SCALEUNIT, 110*SCALEUNIT);
    maskLayer.path = maskPath.CGPath;
    headImgView.layer.mask = maskLayer;
    _headImgView = headImgView;
    [self.contentView addSubview:self.headImgView];
    
    UILabel *nameLabel = [[UILabel alloc] init];
    nameLabel.textAlignment = NSTextAlignmentLeft;
    nameLabel.font = [UIFont systemFontOfSize:LoginFont-2];
    nameLabel.textColor = [UIColor colorWithHexString:@"#282828"];
    _nameLabel = nameLabel;
    [self.contentView addSubview:self.nameLabel];
    
    UILabel *phoneLabel = [[UILabel alloc] init];
    phoneLabel.textAlignment = NSTextAlignmentLeft;
    phoneLabel.font = [UIFont systemFontOfSize:LoginFont-3];
    phoneLabel.textColor = [UIColor colorWithHexString:@"#666666"];
    _phoneLabel = phoneLabel;
    [self.contentView addSubview:self.phoneLabel];
    
    UILabel *areaLabel = [[UILabel alloc] init];
    areaLabel.textAlignment = NSTextAlignmentLeft;
    areaLabel.font = [UIFont systemFontOfSize:LoginFont-3];
    areaLabel.textColor = [UIColor colorWithHexString:@"#666666"];
    _areaLabel = areaLabel;
    [self.contentView addSubview:self.areaLabel];
    
    UILabel *carLabel = [[UILabel alloc] init];
    carLabel.textAlignment = NSTextAlignmentLeft;
    carLabel.font = [UIFont systemFontOfSize:LoginFont-3];
    carLabel.textColor = [UIColor colorWithHexString:@"#666666"];
    _carLabel = carLabel;
    [self.contentView addSubview:self.carLabel];
    
    UILabel *subjectLabel = [[UILabel alloc] init];
    subjectLabel.textAlignment = NSTextAlignmentLeft;
    subjectLabel.font = [UIFont systemFontOfSize:LoginFont-3];
    subjectLabel.textColor = [UIColor colorWithHexString:@"#666666"];
    _subjectLabel = subjectLabel;
    [self.contentView addSubview:self.subjectLabel];
    
    UILabel *achievementLabel = [[UILabel alloc] init];
    achievementLabel.textAlignment = NSTextAlignmentCenter;
    achievementLabel.font = [UIFont systemFontOfSize:LoginFont+8];
    achievementLabel.textColor = [UIColor colorWithHexString:@"#21d4a4"];
    achievementLabel.layer.borderColor = [UIColor colorWithHexString:@"#21d4a4"].CGColor;
    achievementLabel.layer.borderWidth = SCALEUNIT*2;
    achievementLabel.layer.masksToBounds = YES;
    achievementLabel.layer.cornerRadius = 75*SCALEUNIT;
//    UIBezierPath *berPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, 150*SCALEUNIT, 150*SCALEUNIT) byRoundingCorners:UIRectCornerAllCorners cornerRadii:CGSizeMake(75*SCALEUNIT, 75*SCALEUNIT)];
//    CAShapeLayer *maskLayert = [[CAShapeLayer alloc] init];
//    maskLayert.frame = CGRectMake(0, 0, 150*SCALEUNIT, 150*SCALEUNIT);
//    maskLayert.lineWidth = SCALEUNIT*2;
//    maskLayert.strokeColor = [UIColor colorWithHexString:@"#21d4a4"].CGColor;
//    maskLayert.fillColor = [UIColor clearColor].CGColor;
//    maskLayert.path = berPath.CGPath;
//    achievementLabel.layer.mask = maskLayer;
    _achievementLabel = achievementLabel;
    [self.contentView addSubview:self.achievementLabel];
    
    //布局
    WS(ws);
    [self.headImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.mas_equalTo(ws.contentView).with.offset(30*SCALEUNIT);
        make.size.mas_equalTo(CGSizeMake(110*SCALEUNIT, 110*SCALEUNIT));
    }];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(ws.headImgView);
        make.left.mas_equalTo(ws.headImgView.mas_right).with.offset(20*SCALEUNIT);
        make.size.mas_equalTo(CGSizeMake(500*SCALEUNIT, 64*SCALEUNIT));
    }];
    [self.phoneLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.headImgView.mas_bottom).with.offset(20*SCALEUNIT);
        make.left.mas_equalTo(ws.headImgView);
        make.size.mas_equalTo(CGSizeMake(375*SCALEUNIT, 50*SCALEUNIT));
    }];
    [self.areaLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.phoneLabel.mas_bottom);
        make.left.mas_equalTo(ws.headImgView);
        make.size.mas_equalTo(CGSizeMake(375*SCALEUNIT, 50*SCALEUNIT));
    }];
    [self.carLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.areaLabel.mas_bottom);
        make.left.mas_equalTo(ws.headImgView);
        make.size.mas_equalTo(CGSizeMake(375*SCALEUNIT, 50*SCALEUNIT));
    }];
    [self.subjectLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.carLabel.mas_bottom);
        make.left.mas_equalTo(ws.headImgView);
        make.size.mas_equalTo(CGSizeMake(375*SCALEUNIT, 50*SCALEUNIT));
    }];
    [self.achievementLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(ws.phoneLabel.mas_top).with.offset(25*SCALEUNIT);
        make.right.mas_equalTo(ws.contentView).with.offset(-35*SCALEUNIT);
        make.size.mas_equalTo(CGSizeMake(150*SCALEUNIT, 150*SCALEUNIT));
    }];
}

#pragma mark ==========数据填充==========
- (void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    if (_dataDic != nil) {
        [self.headImgView sd_setImageWithURL:[NSURL URLWithString:[_dataDic objectForKey:@"imgPath"]] placeholderImage:[UIImage imageNamed:@"TeachManagementHeaderImage"]];
        self.nameLabel.text = [_dataDic objectForKey:@"userName"];
        self.phoneLabel.text = [NSString stringWithFormat:@"联系电话：%@",[_dataDic objectForKey:@"phoneNo"]];
        self.areaLabel.text = [NSString stringWithFormat:@"模拟场地：%@",[_dataDic objectForKey:@"schoolName"]];
        self.carLabel.text = [NSString stringWithFormat:@"模拟车辆：%@",[_dataDic objectForKey:@"carTypeName"]];
        self.subjectLabel.text = [NSString stringWithFormat:@"科目类型：%@",[[_dataDic objectForKey:@"subjectType"] integerValue]==2?@"科目二":@"科目三"];
        self.achievementLabel.text = [NSString stringWithFormat:@"%@",[_dataDic objectForKey:@"mockScore"]];
    }
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
